From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934773AbdDFNkd (ORCPT ); Thu, 6 Apr 2017 09:40:33 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:55401 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753213AbdDFNkZ (ORCPT ); Thu, 6 Apr 2017 09:40:25 -0400 Date: Thu, 6 Apr 2017 06:40:24 -0700 From: Matthew Wilcox To: "Huang, Ying" Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dave Hansen , Hugh Dickins , Shaohua Li , Minchan Kim , Rik van Riel Subject: Re: [PATCH -mm -v2] mm, swap: Use kvzalloc to allocate some swap data structure Message-ID: <20170406134024.GD31725@bombadil.infradead.org> References: <20170405071058.25223-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170405071058.25223-1-ying.huang@intel.com> User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 05, 2017 at 03:10:58PM +0800, Huang, Ying wrote: > In general, kmalloc() will have less memory fragmentation than > vmalloc(). From Dave Hansen: For example, we have a two-page data > structure. vmalloc() takes two effectively random order-0 pages, > probably from two different 2M pages and pins them. That "kills" two > 2M pages. kmalloc(), allocating two *contiguous* pages, is very > unlikely to cross a 2M boundary (it theoretically could). That means > it will only "kill" the possibility of a single 2M page. More 2M > pages == less fragmentation. Wait, what? How does kmalloc() manage to allocate two pages that cross a 2MB boundary? AFAIK if you ask kmalloc to allocate N pages, it asks the page allocator for an order-log(N) page allocation. Being a buddy allocator, that comes back with an aligned set of pages. There's no way it can get the last page from a 2MB region and the first page from the next 2MB region.