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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DF13C433DF for ; Wed, 27 May 2020 22:34:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3F04220707 for ; Wed, 27 May 2020 22:34:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="KiKH1jpd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F04220707 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=fb.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F1E15800B9; Wed, 27 May 2020 18:34:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7F1C80010; Wed, 27 May 2020 18:34:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD0AF800B9; Wed, 27 May 2020 18:34:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0244.hostedemail.com [216.40.44.244]) by kanga.kvack.org (Postfix) with ESMTP id B06E280010 for ; Wed, 27 May 2020 18:34:15 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 62A7F180AD817 for ; Wed, 27 May 2020 22:34:15 +0000 (UTC) X-FDA: 76863953670.22.shoes74_7c61d6a0e6d08 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 4310318038E71 for ; Wed, 27 May 2020 22:34:15 +0000 (UTC) X-HE-Tag: shoes74_7c61d6a0e6d08 X-Filterd-Recvd-Size: 7959 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 May 2020 22:34:14 +0000 (UTC) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04RME0Kg016708 for ; Wed, 27 May 2020 15:34:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=d6l00WkVLgtmYXyZnmkXhIoFuaUk1sBZ4g/dXP9ISL4=; b=KiKH1jpdQAbFjBCYFHSvKyAb5M5AGSBvM3W3OCuVe1POQniJMuBwijkRthuho1GIRf+K SjxC8Dv77fHUUd4K8nZCnU/qLcAnId+WBmpBVIfjKtNZVXpI2p5xNKzZGavL005ylwNL JLBlJeZehSf+0bZZnMroQuvD7WsekBqtX7s= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 317ktaj67e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 27 May 2020 15:34:13 -0700 Received: from intmgw002.06.prn3.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 27 May 2020 15:34:11 -0700 Received: by devvm1291.vll0.facebook.com (Postfix, from userid 111017) id 9A8E0166901C; Wed, 27 May 2020 15:34:07 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm1291.vll0.facebook.com To: Andrew Morton , Christoph Lameter CC: Johannes Weiner , Michal Hocko , Shakeel Butt , , Vlastimil Babka , , , Roman Gushchin Smtp-Origin-Cluster: vll0c01 Subject: [PATCH v5 04/19] mm: slub: implement SLUB version of obj_to_index() Date: Wed, 27 May 2020 15:33:49 -0700 Message-ID: <20200527223404.1008856-5-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200527223404.1008856-1-guro@fb.com> References: <20200527223404.1008856-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-05-27_03:2020-05-27,2020-05-27 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 suspectscore=2 mlxlogscore=853 clxscore=1015 spamscore=0 adultscore=0 bulkscore=0 mlxscore=0 cotscore=-2147483648 priorityscore=1501 phishscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005270170 X-FB-Internal: deliver X-Rspamd-Queue-Id: 4310318038E71 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: 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. Vlastimil Babka noticed, that SLUB does have already a similar function called slab_index(), which is defined only if SLUB_DEBUG is enabled. The function does a similar math, but with a division, and it also takes a page address instead of a page pointer. Let's remove slab_index() and replace it with the new helper __obj_to_index(), which takes a page address. obj_to_index() will be a simple wrapper taking a page pointer and passing page_address(page) into __obj_to_index(). Signed-off-by: Roman Gushchin Reviewed-by: Vlastimil Babka Acked-by: Johannes Weiner --- include/linux/slub_def.h | 16 ++++++++++++++++ mm/slub.c | 15 +++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h index d2153789bd9f..30e91c83d401 100644 --- a/include/linux/slub_def.h +++ b/include/linux/slub_def.h @@ -8,6 +8,7 @@ * (C) 2007 SGI, Christoph Lameter */ #include +#include =20 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,18 @@ static inline void *nearest_obj(struct kmem_cache *c= ache, struct page *page, return result; } =20 +/* Determine object index from a given position */ +static inline unsigned int __obj_to_index(const struct kmem_cache *cache= , + void *addr, void *obj) +{ + return reciprocal_divide(kasan_reset_tag(obj) - addr, + cache->reciprocal_size); +} + +static inline unsigned int obj_to_index(const struct kmem_cache *cache, + const struct page *page, void *obj) +{ + return __obj_to_index(cache, page_address(page), obj); +} + #endif /* _LINUX_SLUB_DEF_H */ diff --git a/mm/slub.c b/mm/slub.c index dbed2cfd2776..601c0fc3c83a 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -313,12 +313,6 @@ static inline void set_freepointer(struct kmem_cache= *s, void *object, void *fp) __p < (__addr) + (__objects) * (__s)->size; \ __p +=3D (__s)->size) =20 -/* Determine object index from a given position */ -static inline unsigned int slab_index(void *p, struct kmem_cache *s, voi= d *addr) -{ - return (kasan_reset_tag(p) - addr) / s->size; -} - static inline unsigned int order_objects(unsigned int order, unsigned in= t size) { return ((unsigned int)PAGE_SIZE << order) / size; @@ -461,7 +455,7 @@ static unsigned long *get_map(struct kmem_cache *s, s= truct page *page) bitmap_zero(object_map, page->objects); =20 for (p =3D page->freelist; p; p =3D get_freepointer(s, p)) - set_bit(slab_index(p, s, addr), object_map); + set_bit(__obj_to_index(s, addr, p), object_map); =20 return object_map; } @@ -3675,6 +3669,7 @@ static int calculate_sizes(struct kmem_cache *s, in= t forced_order) */ size =3D ALIGN(size, s->align); s->size =3D size; + s->reciprocal_size =3D reciprocal_value(size); if (forced_order >=3D 0) order =3D forced_order; else @@ -3781,7 +3776,7 @@ static void list_slab_objects(struct kmem_cache *s,= struct page *page, map =3D get_map(s, page); for_each_object(p, s, addr, page->objects) { =20 - if (!test_bit(slab_index(p, s, addr), map)) { + if (!test_bit(__obj_to_index(s, addr, p), map)) { pr_err("INFO: Object 0x%p @offset=3D%tu\n", p, p - addr); print_tracking(s, p); } @@ -4506,7 +4501,7 @@ static void validate_slab(struct kmem_cache *s, str= uct page *page) /* Now we know that a valid freelist exists */ map =3D get_map(s, page); for_each_object(p, s, addr, page->objects) { - u8 val =3D test_bit(slab_index(p, s, addr), map) ? + u8 val =3D test_bit(__obj_to_index(s, addr, p), map) ? SLUB_RED_INACTIVE : SLUB_RED_ACTIVE; =20 if (!check_object(s, page, p, val)) @@ -4697,7 +4692,7 @@ static void process_slab(struct loc_track *t, struc= t kmem_cache *s, =20 map =3D get_map(s, page); for_each_object(p, s, addr, page->objects) - if (!test_bit(slab_index(p, s, addr), map)) + if (!test_bit(__obj_to_index(s, addr, p), map)) add_location(t, s, get_track(s, p, alloc)); put_map(map); } --=20 2.25.4