Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp511927pxy; Sat, 31 Jul 2021 15:20:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtPtONFGGyWeqWDD669ugGabONInjGjbkKChrFIZqCoGZo1CwBWH0bFBsMUOyNuik4EUiB X-Received: by 2002:a05:6e02:2188:: with SMTP id j8mr1686549ila.14.1627770034031; Sat, 31 Jul 2021 15:20:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627770034; cv=none; d=google.com; s=arc-20160816; b=ibVh7Y3VbNIbUmYhyq1RtxQN3H6uQAzrws8hYAPKIROVdBol7v3b8srbJZwFoSgbLD bzVGDhA+Vqrd+cIeUTXF3v0nzKYb0xOGhBLmf0Jd6G93+EiBdx9mlOVAiFB4Ceu3KpOx NaigWRTlfZv6Bsw89M9hF31h0x22mSaLpVnm6xoVoObTagIv9HjohtZto+FG8s5/+r84 UuBOQnGnhHlzPhCKLbTZL+rPseM3Mvr8r9gxWe9AeHIxxVMebGlsSKZi/gRp7/UPklea II69NCY2bdNT6VOmzAU+zO/D+gKkGrQ+97Kz0mL0+7P9dkejSn2KpmJJi346v7nXOTLS NI7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kj+6/3nVbAHDzDB9RaYYeUkGi+scXK1USJ3wPAIJqkw=; b=NdycxBxZb1yHAiwxbyE1WMH2GpPIf9ZaZQ8/MCLQbBGKLzLLwQRdJljZis0z1nG6+e ckoIcNQTpleiMofh7e/bLPOc4WcANiZZnh4gedgZh+4jlvD7Cn2Y2n7J7v2VTms3XejL Eol9BGFeEvvdEkExCTXR2WCNf8X6prwozlRgW51PBwjsyTX4WvqJHoMP00cDGHBGOqTx tyQItxGrmEPQpucqyx/yO7KzePkK0zxkR3YckClRcWyoF4xvCavyi91h/0yyfEKLJHSJ y/iX3CnwO1et7Ziqoopi4Dt7jvtTwr9Su/CgvbcHWF8sgmvvuScxJoxHmz7kKgvF5hG3 cCDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LBhDrqUt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t8si7358274ilu.144.2021.07.31.15.20.11; Sat, 31 Jul 2021 15:20:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LBhDrqUt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229560AbhGaWST (ORCPT + 99 others); Sat, 31 Jul 2021 18:18:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:50206 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbhGaWST (ORCPT ); Sat, 31 Jul 2021 18:18:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BF0EB60EBC; Sat, 31 Jul 2021 22:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627769892; bh=Pud8xtGP3Uc9/7WKiVauc4aaKsBW/kEwyrH3U5Z8Lf4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LBhDrqUtUAHAn9AZXyT5FY/XjnSTQ+w4uuEhA/MeWasr2MIMtEu754qQJta0kU24l NGQuK+ok20YVwA35soSdRCgQ3YSHcZKH7E7+5mwUNl2JIo133vlb2ZT7hvPAiC3GT+ 1VAH6xR40vi0wKE0VVt/NiU+pu0AlS+AaghK+fjS79jNnoelilYrINxO2aF1Glh54q FnrhNu5OYLoyO4JqI7wyUgP4mdG9n/ZP3iQuA3VcmWBgT6JyWtBdFDZa0uMd749Gd+ XwEh+hiDi5FQVVVKzDTwF6JJLx1pjfYf2B+EL98AHXzOYkstZoG6MVuWJh5zZFFZay H3U+OWPjaWmRg== Date: Sat, 31 Jul 2021 15:18:06 -0700 From: Nathan Chancellor To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, cl@linux.com, guro@fb.com, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, mhocko@suse.com, mm-commits@vger.kernel.org, penberg@kernel.org, rientjes@google.com, shakeelb@google.com, songmuchun@bytedance.com, torvalds@linux-foundation.org, vbabka@suse.cz Subject: Re: [patch 6/7] slub: fix unreclaimable slab stat for bulk free Message-ID: References: <20210729145259.24681c326dc3ed18194cf9e5@linux-foundation.org> <20210729215350.SZC9InNuL%akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210729215350.SZC9InNuL%akpm@linux-foundation.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 29, 2021 at 02:53:50PM -0700, Andrew Morton wrote: > From: Shakeel Butt > Subject: slub: fix unreclaimable slab stat for bulk free > > SLUB uses page allocator for higher order allocations and update > unreclaimable slab stat for such allocations. At the moment, the bulk > free for SLUB does not share code with normal free code path for these > type of allocations and have missed the stat update. So, fix the stat > update by common code. The user visible impact of the bug is the > potential of inconsistent unreclaimable slab stat visible through meminfo > and vmstat. > > Link: https://lkml.kernel.org/r/20210728155354.3440560-1-shakeelb@google.com > Fixes: 6a486c0ad4dc ("mm, sl[ou]b: improve memory accounting") > Signed-off-by: Shakeel Butt > Acked-by: Michal Hocko > Acked-by: Roman Gushchin > Reviewed-by: Muchun Song > Cc: Christoph Lameter > Cc: Pekka Enberg > Cc: David Rientjes > Cc: Joonsoo Kim > Cc: Vlastimil Babka > Signed-off-by: Andrew Morton > --- > > mm/slub.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > --- a/mm/slub.c~slub-fix-unreclaimable-slab-stat-for-bulk-free > +++ a/mm/slub.c > @@ -3236,6 +3236,16 @@ struct detached_freelist { > struct kmem_cache *s; > }; > > +static inline void free_nonslab_page(struct page *page) > +{ > + unsigned int order = compound_order(page); > + > + VM_BUG_ON_PAGE(!PageCompound(page), page); > + kfree_hook(page_address(page)); > + mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order)); > + __free_pages(page, order); > +} > + > /* > * This function progressively scans the array with free objects (with > * a limited look ahead) and extract objects belonging to the same > @@ -3272,9 +3282,7 @@ int build_detached_freelist(struct kmem_ > if (!s) { > /* Handle kalloc'ed objects */ > if (unlikely(!PageSlab(page))) { > - BUG_ON(!PageCompound(page)); > - kfree_hook(object); > - __free_pages(page, compound_order(page)); > + free_nonslab_page(page); > p[size] = NULL; /* mark object processed */ > return size; > } > @@ -4250,13 +4258,7 @@ void kfree(const void *x) > > page = virt_to_head_page(x); > if (unlikely(!PageSlab(page))) { > - unsigned int order = compound_order(page); > - > - BUG_ON(!PageCompound(page)); > - kfree_hook(object); > - mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, > - -(PAGE_SIZE << order)); > - __free_pages(page, order); > + free_nonslab_page(page); > return; > } > slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_); > _ This patch, now in mainline as commit f227f0faf63b ("slub: fix unreclaimable slab stat for bulk free") causes the KASAN KUnit test kmalloc_pagealloc_invalid_free to no longer fail: [ 0.000000] Linux version 5.14.0-rc3-00066-gf227f0faf63b (nathan@archlinux-ax161) (x86_64-linux-gcc (GCC) 11.2.0, GNU ld (GNU Binutils) 2.37) #1 SMP Sat Jul 31 15:08:11 MST 2021 ... [ 5.717678] # kmalloc_pagealloc_invalid_free: EXPECTATION FAILED at lib/test_kasan.c:203 [ 5.717678] KASAN failure expected in "kfree(ptr + 1)", but none occurred [ 5.718909] not ok 6 - kmalloc_pagealloc_invalid_free ... [ 9.481520] not ok 1 - kasan The previous commit is fine: [ 0.000000] Linux version 5.14.0-rc3-00065-gb5916c025432 (nathan@archlinux-ax161) (x86_64-linux-gcc (GCC) 11.2.0, GNU ld (GNU Binutils) 2.37) #1 SMP Sat Jul 31 15:05:09 MST 2021 ... [ 9.347598] ok 1 - kasan I am by no means a KASAN or mm/ expert, I noticed this when trying to test KASAN with clang for ClangBuiltLinux's CI, so it does not appear to be compiler dependent. It is reproducible for me in QEMU with x86_64_defconfig + CONFIG_KASAN=y + CONFIG_KUNIT=y + CONFIG_KASAN_KUNIT_TEST=y. Please let me know if there is any other information I can provide or testing I can do. Cheers, Nathan