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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 3C091C43460 for ; Thu, 8 Apr 2021 03:57:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C96F5610FA for ; Thu, 8 Apr 2021 03:57:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C96F5610FA 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 E7BFE6B0080; Wed, 7 Apr 2021 23:57:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE7FA8D0001; Wed, 7 Apr 2021 23:57:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B01906B0082; Wed, 7 Apr 2021 23:57:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id 7AFD28E0003 for ; Wed, 7 Apr 2021 23:57:51 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 36B215DF5 for ; Thu, 8 Apr 2021 03:57:51 +0000 (UTC) X-FDA: 78007841142.18.28871F2 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf22.hostedemail.com (Postfix) with ESMTP id 98F51C0001EE for ; Thu, 8 Apr 2021 03:57:48 +0000 (UTC) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 1383qcZL010009 for ; Wed, 7 Apr 2021 20:57:49 -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=nfieNUNbNb1D09215aq0Md0ODibFOEFLCBSQhP0UblY=; b=Ei+F+GPAXOR6U7V8sokiEiHmPHl3xizv7f+HIBM04VR4nK3TayJLBK9RopBf9i3a5UDo Kq0KHkMK+f26xQi1M9w4ZL2apqcBTVTgbILwGMd985t/fA6sgCty2ER6aRK9sXmkXU02 qDTzAdVkfAUsLfK4Vfr/CDU5ZVfrC3tBJ+M= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 37sf0qm5cq-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 07 Apr 2021 20:57:49 -0700 Received: from intmgw002.46.prn1.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:11d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 7 Apr 2021 20:57:47 -0700 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id 6D269602B014; Wed, 7 Apr 2021 20:57:41 -0700 (PDT) From: Roman Gushchin To: Dennis Zhou CC: Tejun Heo , Christoph Lameter , Andrew Morton , Vlastimil Babka , , , Roman Gushchin Subject: [PATCH v3 5/6] percpu: factor out pcpu_check_chunk_hint() Date: Wed, 7 Apr 2021 20:57:35 -0700 Message-ID: <20210408035736.883861-6-guro@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408035736.883861-1-guro@fb.com> References: <20210408035736.883861-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: DHrS6iLFNTzUkjMd-hG8o-O2oBUnPggq X-Proofpoint-ORIG-GUID: DHrS6iLFNTzUkjMd-hG8o-O2oBUnPggq X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-08_01:2021-04-07,2021-04-08 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 suspectscore=0 adultscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104080023 X-FB-Internal: deliver X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 98F51C0001EE X-Stat-Signature: haz14un7iefdgf95sqo7gcwz7fbx7p3g Received-SPF: none (fb.com>: No applicable sender policy available) receiver=imf22; identity=mailfrom; envelope-from=""; helo=mx0a-00082601.pphosted.com; client-ip=67.231.145.42 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617854268-265034 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: Factor out the pcpu_check_chunk_hint() helper, which will be useful in the future. The new function checks if the allocation can likely fit the given chunk. Signed-off-by: Roman Gushchin --- mm/percpu.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index e20119668c42..357fd6994278 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -306,6 +306,26 @@ static unsigned long pcpu_block_off_to_off(int index= , int off) return index * PCPU_BITMAP_BLOCK_BITS + off; } =20 +/** + * pcpu_check_chunk_hint - check that allocation can fit a chunk + * @chunk_md: chunk's block + * @bits: size of request in allocation units + * @align: alignment of area (max PAGE_SIZE) + * + * Check to see if the allocation can fit in the chunk's contig hint. + * This is an optimization to prevent scanning by assuming if it + * cannot fit in the global hint, there is memory pressure and creating + * a new chunk would happen soon. + */ +static bool pcpu_check_chunk_hint(struct pcpu_block_md *chunk_md, int bi= ts, + size_t align) +{ + int bit_off =3D ALIGN(chunk_md->contig_hint_start, align) - + chunk_md->contig_hint_start; + + return bit_off + bits <=3D chunk_md->contig_hint; +} + /* * pcpu_next_hint - determine which hint to use * @block: block of interest @@ -1065,15 +1085,7 @@ static int pcpu_find_block_fit(struct pcpu_chunk *= chunk, int alloc_bits, struct pcpu_block_md *chunk_md =3D &chunk->chunk_md; int bit_off, bits, next_off; =20 - /* - * Check to see if the allocation can fit in the chunk's contig hint. - * This is an optimization to prevent scanning by assuming if it - * cannot fit in the global hint, there is memory pressure and creating - * a new chunk would happen soon. - */ - bit_off =3D ALIGN(chunk_md->contig_hint_start, align) - - chunk_md->contig_hint_start; - if (bit_off + alloc_bits > chunk_md->contig_hint) + if (!pcpu_check_chunk_hint(chunk_md, alloc_bits, align)) return -1; =20 bit_off =3D pcpu_next_hint(chunk_md, alloc_bits); --=20 2.30.2