From patchwork Mon Apr 19 22:50:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 12212777 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=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 E3D5CC43460 for ; Mon, 19 Apr 2021 22:51:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4A69B61090 for ; Mon, 19 Apr 2021 22:51:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A69B61090 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B508D6B0036; Mon, 19 Apr 2021 18:51:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB6FC6B0070; Mon, 19 Apr 2021 18:51:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BAC96B006E; Mon, 19 Apr 2021 18:51:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0099.hostedemail.com [216.40.44.99]) by kanga.kvack.org (Postfix) with ESMTP id 686D66B0036 for ; Mon, 19 Apr 2021 18:51:00 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 199A3363E for ; Mon, 19 Apr 2021 22:51:00 +0000 (UTC) X-FDA: 78050613480.03.79E536F Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) by imf28.hostedemail.com (Postfix) with ESMTP id A529A200024D for ; Mon, 19 Apr 2021 22:51:01 +0000 (UTC) Received: by mail-io1-f43.google.com with SMTP id g125so7890830iof.3 for ; Mon, 19 Apr 2021 15:50:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b7dN1cR8yp1Y0dQfx7nVvl1zLTK95ZK5ZgHF63GsR4I=; b=LJ6oxjyx71v6vqUIIu5P4D3LaP06L1KxnZZTyte3rE19wcvwUz/wAxaW1gCTA6t6Np LdhT4HzZLhoZAMhlb+c7pcTVbFQsCTLR5GSnuGyOb06w1fRSxSKpSJ6iEHY6LLfEZEv7 ZmKEf0fEi59kI/lD3NOrP0rfZAPwqcKlNNPW+iQYNtVdSnuNW3PVCOMcSCfOE1UFAV2V YHA9VoOXQiclen7qMRf2qAjg2fbc/F8NIk8tgLhhdGh+ysAoFPVcQsHjES/E8i00/tQ7 mCZfX/aNA7Dc0pjFiukMPSNN2Pc4Oi/qbeWZpL+eb5FlQMzXW+UvlOxRZenFPzwYYa9Y rwKA== X-Gm-Message-State: AOAM533HXzWwA5fzIRxxPd90NtbE7D5/vxIGxa0J6bm4MxHQGB2CIqOX ypGbnEole+RqANoIPpWTTe8= X-Google-Smtp-Source: ABdhPJxIhJh7EN6HqpS59th3ME8ohUoJNzIxmuknJmCAl850EvjwOREFqhJwTVrTJz1zzXLyEaF3vw== X-Received: by 2002:a02:6c0e:: with SMTP id w14mr9072162jab.4.1618872659021; Mon, 19 Apr 2021 15:50:59 -0700 (PDT) Received: from abasin.c.googlers.com.com (243.199.238.35.bc.googleusercontent.com. [35.238.199.243]) by smtp.gmail.com with ESMTPSA id d7sm7566967ion.39.2021.04.19.15.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 15:50:58 -0700 (PDT) From: Dennis Zhou To: Tejun Heo , Christoph Lameter , Roman Gushchin Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH 1/4] percpu: factor out pcpu_check_block_hint() Date: Mon, 19 Apr 2021 22:50:44 +0000 Message-Id: <20210419225047.3415425-2-dennis@kernel.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog In-Reply-To: <20210419225047.3415425-1-dennis@kernel.org> References: <20210419225047.3415425-1-dennis@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 781maq3ax9qi16z71h1zcj7hccareyru X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A529A200024D Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=mail-io1-f43.google.com; client-ip=209.85.166.43 X-HE-DKIM-Result: none/none X-HE-Tag: 1618872661-712421 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: From: Roman Gushchin Factor out the pcpu_check_block_hint() helper, which will be useful in the future. The new function checks if the allocation can likely fit within the contig hint. Signed-off-by: Roman Gushchin Signed-off-by: Dennis Zhou --- mm/percpu.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index 61339b3d9337..5edc7bd88133 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -306,6 +306,25 @@ static unsigned long pcpu_block_off_to_off(int index, int off) return index * PCPU_BITMAP_BLOCK_BITS + off; } +/** + * pcpu_check_block_hint - check against the contig hint + * @block: block of interest + * @bits: size of allocation + * @align: alignment of area (max PAGE_SIZE) + * + * Check to see if the allocation can fit in the block's contig hint. + * Note, a chunk uses the same hints as a block so this can also check against + * the chunk's contig hint. + */ +static bool pcpu_check_block_hint(struct pcpu_block_md *block, int bits, + size_t align) +{ + int bit_off = ALIGN(block->contig_hint_start, align) - + block->contig_hint_start; + + return bit_off + bits <= block->contig_hint; +} + /* * pcpu_next_hint - determine which hint to use * @block: block of interest @@ -1066,14 +1085,11 @@ static int pcpu_find_block_fit(struct pcpu_chunk *chunk, int alloc_bits, int bit_off, bits, next_off; /* - * 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. + * This is an optimization to prevent scanning by assuming if the + * allocation cannot fit in the global hint, there is memory pressure + * and creating a new chunk would happen soon. */ - bit_off = ALIGN(chunk_md->contig_hint_start, align) - - chunk_md->contig_hint_start; - if (bit_off + alloc_bits > chunk_md->contig_hint) + if (!pcpu_check_block_hint(chunk_md, alloc_bits, align)) return -1; bit_off = pcpu_next_hint(chunk_md, alloc_bits);