From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: hugetlbfs not working Date: Thu, 27 Mar 2008 18:55:10 -0300 Message-ID: <20080327215510.GA11511@dmt> References: <47EBBB1A.30109@qumranet.com> <80C24060-EF44-44C5-96E2-C629F0A52EBD@csgraf.de> <47EBC626.4010801@codemonkey.ws> <47EBC6D4.3070803@qumranet.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel , Alexander Graf To: Avi Kivity Return-path: Content-Disposition: inline In-Reply-To: <47EBC6D4.3070803@qumranet.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org On Thu, Mar 27, 2008 at 06:09:56PM +0200, Avi Kivity wrote: > Anthony Liguori wrote: > > > > If you don't bail when ftruncate fails, does it work as expected for > > you? Perhaps older versions of hugetlbfs didn't support truncate. > > If you don't truncate, how can you change the file size? hugetlbfs > doesn't support write(). > > I vaugely recall using ftruncate() on 2.4. commit 7aa91e104028b87ff13f5eeb7a0d7ffe7b5a2348 Author: Ken Chen Date: Tue Oct 16 01:26:21 2007 -0700 hugetlb: allow extending ftruncate on hugetlbfs For historical reason, expanding ftruncate that increases file size on hugetlbfs is not allowed due to pages were pre-faulted and lack of fault handler. Now that we have demand faulting on hugetlb since 2.6.15, there is no reason to hold back that limitation. This will make hugetlbfs behave more like a normal fs. I'm writing a user level code that uses hugetlbfs but will fall back to tmpfs if there are no hugetlb page available in the system. Having hugetlbfs specific ftruncate behavior is a bit quirky and I would like to remove that artificial limitation. Signed-off-by: Acked-by: Wiliam Irwin Cc: Adam Litke Cc: David Gibson Cc: Nishanth Aravamudan Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds mmap() should fail if anything goes wrong with ftruncate and the file length is not extented on tmpfs. --- vl.c.orig 2008-03-27 18:51:31.000000000 -0300 +++ vl.c 2008-03-27 18:52:40.000000000 -0300 @@ -8749,11 +8749,7 @@ memory = (memory+hpagesize-1) & ~(hpagesize-1); - if (ftruncate(fd, memory) == -1) { - perror("ftruncate"); - close(fd); - return NULL; - } + ftruncate(fd, memory); area = mmap(0, memory, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); if (area == MAP_FAILED) { ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace