Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp573934ybk; Wed, 20 May 2020 06:55:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZw4DmSv2qwxdOuCwe1XBTcy36inQtB992XWr8/5QDfyaqfjpUf6jSqD1Y6hA4OZ0VvfJF X-Received: by 2002:a50:8165:: with SMTP id 92mr3555257edc.263.1589982931562; Wed, 20 May 2020 06:55:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589982931; cv=none; d=google.com; s=arc-20160816; b=odzTLPBtE/ug8o5VyVedc9lZjVlximyTwLAxXnKxH3GrjWrl8XsUVMWJd8X6CGHhow kAfihOcLCocgZe4x8lemaB9koLy8965sctc8C5pDTx5pFnbaQStLIRKd5hWBUjgthOPv ZO8THVCynQkjosIUueSUFdGhaI1t9B2yvcgyb26LOQKosLhIVYOy5QEHa5rtoLibzhCq diDpg0aANfefVctDeyYoEzD4k9KnRNAM0cmaaz3Pd+zsei0IATvx4NfgGNqdKemMbay5 V06DEJt5/ICWTJSVEQkc1lfxObavuXX3jXRPdU6AQr/MOTOLT2IADyh5GNSqFRI5sLbG BeTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=j4BBU95wZizsP4FEoqfFeB9x1ZZx4LXpVYCZZW7n7zI=; b=lNHC4PYM1U27kGqWmeXtIi8VsiUtlV72SHOCDPQqbgiRI1VHImqx8ziNlHXP/rCzry ySgTzXGL1inFhzB/lRZFO1UJ3ueI3OSt0i66+MiGRjurqj9tnIRseOqSB8iMsXJMvG1Y +kR0u9ATGrxrvgy+cNHMlAJnWGI9Wcw95kRFCwilb9pDscfXABJfBZyJEvs7lwvtJNk+ E/aCjS4Vbo9YrOpvia09KpBk2nNnk+9bcYAntF/mkn4MsPkhbfgc/pAzajiQolPVPNCG whkd4DKYISWaBrrzREXVvPMxIXWOdNIi6jfYsVevsUy38wSRsQeciPc4KyhQ+cyyfL7o Xz0A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r24si1283992edo.6.2020.05.20.06.55.08; Wed, 20 May 2020 06:55:31 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726819AbgETNvs (ORCPT + 99 others); Wed, 20 May 2020 09:51:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:55290 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726510AbgETNvs (ORCPT ); Wed, 20 May 2020 09:51:48 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5774FAC46; Wed, 20 May 2020 13:51:49 +0000 (UTC) Subject: Re: [PATCH v3 04/19] mm: slub: implement SLUB version of obj_to_index() To: Roman Gushchin , Andrew Morton Cc: Johannes Weiner , Michal Hocko , linux-mm@kvack.org, kernel-team@fb.com, linux-kernel@vger.kernel.org, Christoph Lameter References: <20200422204708.2176080-1-guro@fb.com> <20200422204708.2176080-5-guro@fb.com> From: Vlastimil Babka Message-ID: <0e0616f2-6c5a-8911-7d37-6f2027c2930b@suse.cz> Date: Wed, 20 May 2020 15:51:45 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200422204708.2176080-5-guro@fb.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/22/20 10:46 PM, Roman Gushchin wrote: > This commit implements SLUB version of the obj_to_index() function, > which will be required to calculate the offset of obj_cgroup in the > obj_cgroups vector to store/obtain the objcg ownership data. > > To make it faster, let's repeat the SLAB's trick introduced by > commit 6a2d7a955d8d ("[PATCH] SLAB: use a multiply instead of a > divide in obj_to_index()") and avoid an expensive division. > > Signed-off-by: Roman Gushchin > Acked-by: Christoph Lameter > Acked-by: Johannes Weiner There's already a slab_index() doing the same without the trick, with only SLUB_DEBUG callers. Maybe just improve it and perhaps rename? (obj_to_index() seems more descriptive). The difference is that it takes the result of page_addr() instead of doing that, as it's being called in a loop on objects from a single page, so you'd have to perhaps split to obj_to_index(page) and __obj_to_index(addr) or something. > --- > include/linux/slub_def.h | 9 +++++++++ > mm/slub.c | 1 + > 2 files changed, 10 insertions(+) > > diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h > index d2153789bd9f..200ea292f250 100644 > --- a/include/linux/slub_def.h > +++ b/include/linux/slub_def.h > @@ -8,6 +8,7 @@ > * (C) 2007 SGI, Christoph Lameter > */ > #include > +#include > > enum stat_item { > ALLOC_FASTPATH, /* Allocation from cpu slab */ > @@ -86,6 +87,7 @@ struct kmem_cache { > unsigned long min_partial; > unsigned int size; /* The size of an object including metadata */ > unsigned int object_size;/* The size of an object without metadata */ > + struct reciprocal_value reciprocal_size; > unsigned int offset; /* Free pointer offset */ > #ifdef CONFIG_SLUB_CPU_PARTIAL > /* Number of per cpu partial objects to keep around */ > @@ -182,4 +184,11 @@ static inline void *nearest_obj(struct kmem_cache *cache, struct page *page, > return result; > } > > +static inline unsigned int obj_to_index(const struct kmem_cache *cache, > + const struct page *page, void *obj) > +{ > + return reciprocal_divide(kasan_reset_tag(obj) - page_address(page), > + cache->reciprocal_size); > +} > + > #endif /* _LINUX_SLUB_DEF_H */ > diff --git a/mm/slub.c b/mm/slub.c > index 03071ae5ff07..8d16babe1829 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -3660,6 +3660,7 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order) > */ > size = ALIGN(size, s->align); > s->size = size; > + s->reciprocal_size = reciprocal_value(size); > if (forced_order >= 0) > order = forced_order; > else >