From patchwork Wed Feb 3 21:08:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12065373 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 94721C433DB for ; Wed, 3 Feb 2021 21:08:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EDFD261477 for ; Wed, 3 Feb 2021 21:08:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDFD261477 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 30AC26B0005; Wed, 3 Feb 2021 16:08:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B9796B006C; Wed, 3 Feb 2021 16:08:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1836F6B006E; Wed, 3 Feb 2021 16:08:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id F348C6B0005 for ; Wed, 3 Feb 2021 16:08:40 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B13DA181AEF15 for ; Wed, 3 Feb 2021 21:08:40 +0000 (UTC) X-FDA: 77778195600.20.turn20_5a0a8e9275d6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 93144180C07A3 for ; Wed, 3 Feb 2021 21:08:40 +0000 (UTC) X-HE-Tag: turn20_5a0a8e9275d6 X-Filterd-Recvd-Size: 7136 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Wed, 3 Feb 2021 21:08:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612386519; h=from:from: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; bh=hi+7C1TTEkkl4WRac4WQ2x2QuL/BvKdq/6D+mj3cbKc=; b=alhk85diwXDtlJMGANqqSLWSjY4tquHv0OdbASmXjGraN6dCH+0tD8TYxTRpOOi2n1UZtU jPsyK/QVp3mhpyOXAbJteppFmSaknuNi8vO8xLysvEMwr+m6VqIsVAyAQyVnOHiNsExOTp NSimawLczuVjZWYCLDJkfxIJt/rvuCM= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-570-ZbThGZZ8MbqVLrvin3xlrg-1; Wed, 03 Feb 2021 16:08:38 -0500 X-MC-Unique: ZbThGZZ8MbqVLrvin3xlrg-1 Received: by mail-qt1-f197.google.com with SMTP id w3so896885qti.17 for ; Wed, 03 Feb 2021 13:08:38 -0800 (PST) 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=hi+7C1TTEkkl4WRac4WQ2x2QuL/BvKdq/6D+mj3cbKc=; b=DHpRynwxMbyqWqP8DMfIqC1n49v39D96VuwPgHUJKklWypaLhbGZuO71jI9P+1zh8E eyM4kcM5+Q/jmVcngTSONfqXq/LeSB2utcyEuX4GlLhBtJK53iGA2thGuWVcRTuoxZ6h PuJIQr46yAPxTpogecdhXfI0oSyQuETNL1oVaksnKhEAW/K8CkYiHSTLIVy+VAgWpCSH uHG2/19tR7wrznNC39+VKGvQkmSu0PRl+Ua2m8fG00a1cnPsiLGFdAZfKvmiYNApqv/s /r3F3cwpzKP0VYj/0E0uvYNO/TfLZCyNGL3l+uUriNbwACBHCRjfS30TwceOeeOuF7PE +KDw== X-Gm-Message-State: AOAM5317AIzk9gSxLiv2oilbiGxMYruaG8R0DgImYODNCdceyszC1cGK 3seozNOxJ2VmSwufTUOFAvkHuwaYv6gczR7P1SNr+zTpG06z2EGcL2ZoX2lAmPo6QMwcs25yEv4 JYCaIqQwa+Lo= X-Received: by 2002:a05:622a:109:: with SMTP id u9mr4287325qtw.116.1612386517535; Wed, 03 Feb 2021 13:08:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwsK56DJ4Ctms//4+fxvCDxExkPh+ZfRXVZ5RIfd/7b2Jecyo9d2wOQoUVa7DDZ2m6IK7Mk1Q== X-Received: by 2002:a05:622a:109:: with SMTP id u9mr4287296qtw.116.1612386517306; Wed, 03 Feb 2021 13:08:37 -0800 (PST) Received: from xz-x1.redhat.com (bras-vprn-toroon474qw-lp130-20-174-93-89-182.dsl.bell.ca. [174.93.89.182]) by smtp.gmail.com with ESMTPSA id t6sm2507659qti.2.2021.02.03.13.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 13:08:36 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Wei Zhang , Matthew Wilcox , Linus Torvalds , Jason Gunthorpe , Gal Pressman , peterx@redhat.com, Christoph Hellwig , Andrea Arcangeli , Jan Kara , Kirill Shutemov , David Gibson , Mike Rapoport , Mike Kravetz , Kirill Tkhai , Jann Horn , Andrew Morton Subject: [PATCH 1/4] hugetlb: Dedup the code to add a new file_region Date: Wed, 3 Feb 2021 16:08:29 -0500 Message-Id: <20210203210832.113685-2-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210203210832.113685-1-peterx@redhat.com> References: <20210203210832.113685-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: Introduce hugetlb_resv_map_add() helper to add a new file_region rather than duplication the similar code twice in add_reservation_in_range(). Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz Reviewed-by: Miaohe Lin --- mm/hugetlb.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 18f6ee317900..d2859c2aecc9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -321,6 +321,24 @@ static void coalesce_file_region(struct resv_map *resv, struct file_region *rg) } } +static inline long +hugetlb_resv_map_add(struct resv_map *map, struct file_region *rg, long from, + long to, struct hstate *h, struct hugetlb_cgroup *cg, + long *regions_needed) +{ + struct file_region *nrg; + + if (!regions_needed) { + nrg = get_file_region_entry_from_cache(map, from, to); + record_hugetlb_cgroup_uncharge_info(cg, h, map, nrg); + list_add(&nrg->link, rg->link.prev); + coalesce_file_region(map, nrg); + } else + *regions_needed += 1; + + return to - from; +} + /* * Must be called with resv->lock held. * @@ -336,7 +354,7 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t, long add = 0; struct list_head *head = &resv->regions; long last_accounted_offset = f; - struct file_region *rg = NULL, *trg = NULL, *nrg = NULL; + struct file_region *rg = NULL, *trg = NULL; if (regions_needed) *regions_needed = 0; @@ -365,18 +383,11 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t, /* Add an entry for last_accounted_offset -> rg->from, and * update last_accounted_offset. */ - if (rg->from > last_accounted_offset) { - add += rg->from - last_accounted_offset; - if (!regions_needed) { - nrg = get_file_region_entry_from_cache( - resv, last_accounted_offset, rg->from); - record_hugetlb_cgroup_uncharge_info(h_cg, h, - resv, nrg); - list_add(&nrg->link, rg->link.prev); - coalesce_file_region(resv, nrg); - } else - *regions_needed += 1; - } + if (rg->from > last_accounted_offset) + add += hugetlb_resv_map_add(resv, rg, + last_accounted_offset, + rg->from, h, h_cg, + regions_needed); last_accounted_offset = rg->to; } @@ -384,17 +395,9 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t, /* Handle the case where our range extends beyond * last_accounted_offset. */ - if (last_accounted_offset < t) { - add += t - last_accounted_offset; - if (!regions_needed) { - nrg = get_file_region_entry_from_cache( - resv, last_accounted_offset, t); - record_hugetlb_cgroup_uncharge_info(h_cg, h, resv, nrg); - list_add(&nrg->link, rg->link.prev); - coalesce_file_region(resv, nrg); - } else - *regions_needed += 1; - } + if (last_accounted_offset < t) + add += hugetlb_resv_map_add(resv, rg, last_accounted_offset, + t, h, h_cg, regions_needed); VM_BUG_ON(add < 0); return add;