[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <519E3D01.7080101@sr71.net>
Date: Thu, 23 May 2013 09:00:01 -0700
From: Dave Hansen <dave@...1.net>
To: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
CC: Andrea Arcangeli <aarcange@...hat.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Al Viro <viro@...iv.linux.org.uk>,
Hugh Dickins <hughd@...gle.com>,
Wu Fengguang <fengguang.wu@...el.com>, Jan Kara <jack@...e.cz>,
Mel Gorman <mgorman@...e.de>, linux-mm@...ck.org,
Andi Kleen <ak@...ux.intel.com>,
Matthew Wilcox <matthew.r.wilcox@...el.com>,
"Kirill A. Shutemov" <kirill@...temov.name>,
Hillf Danton <dhillf@...il.com>, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCHv4 12/39] thp, mm: rewrite add_to_page_cache_locked() to
support huge pages
On 05/23/2013 07:36 AM, Kirill A. Shutemov wrote:
>>> + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE_PAGECACHE)) {
>>> + BUILD_BUG_ON(HPAGE_CACHE_NR > RADIX_TREE_PRELOAD_NR);
>>> + nr = hpage_nr_pages(page);
>>> + } else {
>>> + BUG_ON(PageTransHuge(page));
>>> + nr = 1;
>>> + }
>>
>> Why can't this just be
>>
>> nr = hpage_nr_pages(page);
>>
>> Are you trying to optimize for the THP=y, but THP-pagecache=n case?
>
> Yes, I try to optimize for the case.
I'd suggest either optimizing in _common_ code, or not optimizing it at
all. Once in production, and all the config options are on, the
optimization goes away anyway.
You could create a hpagecache_nr_pages() helper or something I guess.
>>> + }
>>> + __mod_zone_page_state(page_zone(page), NR_FILE_PAGES, nr);
>>> + if (PageTransHuge(page))
>>> + __inc_zone_page_state(page, NR_FILE_TRANSPARENT_HUGEPAGES);
>>> + mapping->nrpages += nr;
>>> + spin_unlock_irq(&mapping->tree_lock);
>>> + radix_tree_preload_end();
>>> + trace_mm_filemap_add_to_page_cache(page);
>>> + return 0;
>>> +err:
>>> + if (i != 0)
>>> + error = -ENOSPC; /* no space for a huge page */
>>> + page_cache_release(page + i);
>>> + page[i].mapping = NULL;
>>
>> I guess it's a slight behaviour change (I think it's harmless) but if
>> you delay doing the page_cache_get() and page[i].mapping= until after
>> the radix tree insertion, you can avoid these two lines.
>
> Hm. I don't think it's safe. The spinlock protects radix-tree against
> modification, but find_get_page() can see it just after
> radix_tree_insert().
Except that the mapping->tree_lock is still held. I don't think
find_get_page() can find it in the radix tree without taking the lock.
> The page is locked and IIUC never uptodate at this point, so nobody will
> be able to do much with it, but leave it without valid ->mapping is a bad
> idea.
->mapping changes are protected by lock_page(). You can't keep
->mapping stable without holding it. If you unlock_page(), you have to
recheck ->mapping after you reacquire the lock.
In other words, I think the code is fine.
>> I'm also trying to figure out how and when you'd actually have to unroll
>> a partial-huge-page worth of radix_tree_insert(). In the small-page
>> case, you can collide with another guy inserting in to the page cache.
>> But, can that happen in the _middle_ of a THP?
>
> E.g. if you enable THP after some uptime, the mapping can contain small pages
> already.
> Or if a process map the file with bad alignement (MAP_FIXED) and touch the
> area, it will get small pages.
Could you put a comment in explaining this case a bit? It's a bit subtle.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists