From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFFD7C19F2B for ; Wed, 27 Jul 2022 14:12:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2ADD694001C; Wed, 27 Jul 2022 10:12:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25D39940012; Wed, 27 Jul 2022 10:12:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FF1E94001C; Wed, 27 Jul 2022 10:12:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 02434940012 for ; Wed, 27 Jul 2022 10:12:50 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CDA0D1A039F for ; Wed, 27 Jul 2022 14:12:49 +0000 (UTC) X-FDA: 79733070858.06.530478A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf03.hostedemail.com (Postfix) with ESMTP id 537312009D for ; Wed, 27 Jul 2022 14:12:49 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5268038923; Wed, 27 Jul 2022 14:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1658931166; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3H98ZbyL+yCoBqBhV71DiorzBZIV17eeA3gst4o8mrk=; b=bgQoHYCprpaw4pMJP0e2jDu5EvkOWB9a3HmUBXACljqsjBUt87bFlkE5Yse6iYZgKl9lQ6 cXQWtvVALZgXOgqbJbTWhboHpJ/pnW60pln1Ll4o0fhJETEDrSrObo7htBWJyCFSZahO+R wirE0MwPArcMHgxaNm8Hl17qgAgc20k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1658931166; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3H98ZbyL+yCoBqBhV71DiorzBZIV17eeA3gst4o8mrk=; b=7+xTh6q4y3M/AUe0+yTtSDDSrDHYe+YQx05ty09JeTaV3FhChgTM05wqgkG3pFsiDqkd1y ZfaEKuYkkTD+UJBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2377313A8E; Wed, 27 Jul 2022 14:12:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MbwLCN5H4WImTgAAMHmgww (envelope-from ); Wed, 27 Jul 2022 14:12:46 +0000 Message-ID: <071e9a19-4aa8-e6c5-2e50-d59e60dca3e2@suse.cz> Date: Wed, 27 Jul 2022 16:12:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3 1/3] mm/slub: enable debugging memory wasting of kmalloc Content-Language: en-US To: Christoph Lameter , Feng Tang Cc: Andrew Morton , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dave Hansen , Robin Murphy , John Garry , Kefeng Wang References: <20220727071042.8796-1-feng.tang@intel.com> <20220727071042.8796-2-feng.tang@intel.com> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=bgQoHYCp; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=7+xTh6q4; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658931169; a=rsa-sha256; cv=none; b=rHvoAqWzmrH23k4ybbhWG/Cr4PxECz32NchKIhYavehZQsx6O+F670/6AVfEIuy4cMpurf zw0siJWSgmA/CtThBzZB3RqkaiUpphD8fVkdpL9rs/u3MsMecm/BkfAO5UDwaYNKy+wJhK bAkWqfSYQ+RAW3qIlG4gYugDINODLoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658931169; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3H98ZbyL+yCoBqBhV71DiorzBZIV17eeA3gst4o8mrk=; b=0C37nU9izavPl0toPDETjSOOOcTozAB+LISgjbowQQMbrdADh6/7a/Uykd7Z2buuDBAWSP W9izGUtHCrEKEw1lzacOZSkly05LbKujfJ1Tz8DaA/AUAL7gmsqOT/xM5sKdSQirJ5l1+w T8e5Gt0q7NVrvOlhmJsSMYQ7DmuHvGg= X-Stat-Signature: ehceyncmu4ojk7o637srjo1dnh4efcj8 X-Rspamd-Queue-Id: 537312009D X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=bgQoHYCp; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=7+xTh6q4; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam02 X-HE-Tag: 1658931169-151805 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 7/27/22 12:20, Christoph Lameter wrote: > On Wed, 27 Jul 2022, Feng Tang wrote: > >> @@ -2905,7 +2950,7 @@ static inline void *get_freelist(struct kmem_cache *s, struct slab *slab) >> * already disabled (which is the case for bulk allocation). >> */ >> static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, >> - unsigned long addr, struct kmem_cache_cpu *c) >> + unsigned long addr, struct kmem_cache_cpu *c, unsigned int orig_size) >> { >> void *freelist; >> struct slab *slab; >> @@ -3102,7 +3147,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, >> * pointer. >> */ >> static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, >> - unsigned long addr, struct kmem_cache_cpu *c) >> + unsigned long addr, struct kmem_cache_cpu *c, unsigned int orig_size) >> { >> void *p; >> >> @@ -3115,7 +3160,7 @@ static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, >> c = slub_get_cpu_ptr(s->cpu_slab); >> #endif >> >> - p = ___slab_alloc(s, gfpflags, node, addr, c); >> + p = ___slab_alloc(s, gfpflags, node, addr, c, orig_size); >> #ifdef CONFIG_PREEMPT_COUNT >> slub_put_cpu_ptr(s->cpu_slab); > > This is modifying and making execution of standard slab functions more > expensive. Could you restrict modifications to the kmalloc subsystem? > > kmem_cache_alloc() and friends are not doing any rounding up to power of > two sizes. > > What is happening here is that you pass kmalloc object size info through > the kmem_cache_alloc functions so that the regular allocation functions > debug functionality can then save the kmalloc specific object request > size. This is active even when no debugging options are enabled. I don't think the extra orig_size parameter (unused for non-debug caches) adds any noticeable overhead. In slab_alloc_node() we already have the orig_size parameter (for both kmalloc and non-kmalloc caches) before this patch, and it remains unused in the cmpxchg based fast path. The patch adds it to __slab_alloc() which is not the fast path, and it's still unused for non-debug caches there. So the overhead is basically one less register available (because of the extra param) in a slow path and that should be immeasurable. > Can you avoid that? Have kmalloc do the object allocation without passing > through the kmalloc request size and then add the original size info > to the debug field later after execution continues in the kmalloc functions? That approach is problematic wrt patches 2+3 if we want to use orig_size to affect the boundaries of zero-init and redzoning. Also it goes against the attempt to fix races wrt validation, see [1] where the idea is to have alloc_debug_processing() including redzoning done under n->list_lock and for that should have orig_size passed there as well. [1] https://lore.kernel.org/all/69462916-2d1c-dd50-2e64-b31c2b61690e@suse.cz/