Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp221156pxb; Sat, 10 Apr 2021 00:26:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmpXXOWKXDt+P4nXklTJgrNMuMXP4cOaPXVc9FqKaaPpQMTID3DA17mWPmllurob/bIwF1 X-Received: by 2002:a65:62d7:: with SMTP id m23mr17112112pgv.244.1618039571114; Sat, 10 Apr 2021 00:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618039571; cv=none; d=google.com; s=arc-20160816; b=ccD+ptAHFVNhLmbNgI7WjIlNLtfYS7A5HjDz+pcneTfhL4umYPy0NGxBMr1BJoc+C6 X+1k9NupYIJ0hmfhJf1tPdkxEMgs2QKUNeoUn/KayGumOftYtzQMk9fqCQ6dfXHoMBEp h2MY6m7UXxX8cdkUrpTXnJFUd/5ZBMF+gys8WBmtPRhMjgH+JBF2IVVl0hTtEucHzV93 W0F2aLig6KluoHUdm/AlvbG9ZPkAEteUg7qDjUE0u23IevwNttogmQrQqy+gL4DXjv6F 7wOkhmiz6mZb1A3Jgnm0JQLkHyQQsrhnEgvvnMfwSugPsiMcIKxEarvuRR86Ly18J4Oi bADg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xyXAqaw7UfJ/dQo8pl7Zmsy5byrTbyHYvDNO6ZQ98cs=; b=JZf7/qMxw1oYCKbhmB4Olm09ITFcqW7XY3tx+ozmCqadZx3Y4yyoo8m0vi5R/fKtQr Svh7gcdg3PrsmIYTVCsgS7nGkTq8QW880y67MtO+jfWtoHTDY9F4RQUDpv/sJeK+/KEi 8VswBB7Coyom3vffDMf0LEcX10YHqkB1A8yNPhk70IC+UpLLZsL0rN5hM+TzzBgoptkz bRK896nnmjWdAeiolPG4vhsT05c2CCJHrsi6PCtPKJRlzxQn7SFQ1kul34dfdQ/lUHPb s6cqBI0qNm8wYHz8BMZG5727+uuJ0/Ov0/9FInUXIz41a3LMiZAOA9V6hufpmc1EeNSC UFMg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si5401643pgk.397.2021.04.10.00.25.45; Sat, 10 Apr 2021 00:26:11 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234416AbhDJHZC (ORCPT + 99 others); Sat, 10 Apr 2021 03:25:02 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:17304 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230235AbhDJHY7 (ORCPT ); Sat, 10 Apr 2021 03:24:59 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FHRKK0tJvz9xLy; Sat, 10 Apr 2021 15:22:29 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.498.0; Sat, 10 Apr 2021 15:24:36 +0800 From: Miaohe Lin To: , CC: , , , Subject: [PATCH v2 2/5] mm/hugeltb: simplify the return code of __vma_reservation_common() Date: Sat, 10 Apr 2021 03:23:45 -0400 Message-ID: <20210410072348.20437-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20210410072348.20437-1-linmiaohe@huawei.com> References: <20210410072348.20437-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's guaranteed that the vma is associated with a resv_map, i.e. either VM_MAYSHARE or HPAGE_RESV_OWNER, when the code reaches here or we would have returned via !resv check above. So it's unneeded to check whether HPAGE_RESV_OWNER is set here. Simplify the return code to make it more clear. Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a03a50b7c410..9b4c05699a90 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2163,27 +2163,26 @@ static long __vma_reservation_common(struct hstate *h, if (vma->vm_flags & VM_MAYSHARE) return ret; - else if (is_vma_resv_set(vma, HPAGE_RESV_OWNER) && ret >= 0) { - /* - * In most cases, reserves always exist for private mappings. - * However, a file associated with mapping could have been - * hole punched or truncated after reserves were consumed. - * As subsequent fault on such a range will not use reserves. - * Subtle - The reserve map for private mappings has the - * opposite meaning than that of shared mappings. If NO - * entry is in the reserve map, it means a reservation exists. - * If an entry exists in the reserve map, it means the - * reservation has already been consumed. As a result, the - * return value of this routine is the opposite of the - * value returned from reserve map manipulation routines above. - */ - if (ret) - return 0; - else - return 1; - } - else - return ret < 0 ? ret : 0; + /* + * We know private mapping must have HPAGE_RESV_OWNER set. + * + * In most cases, reserves always exist for private mappings. + * However, a file associated with mapping could have been + * hole punched or truncated after reserves were consumed. + * As subsequent fault on such a range will not use reserves. + * Subtle - The reserve map for private mappings has the + * opposite meaning than that of shared mappings. If NO + * entry is in the reserve map, it means a reservation exists. + * If an entry exists in the reserve map, it means the + * reservation has already been consumed. As a result, the + * return value of this routine is the opposite of the + * value returned from reserve map manipulation routines above. + */ + if (ret > 0) + return 0; + if (ret == 0) + return 1; + return ret; } static long vma_needs_reservation(struct hstate *h, -- 2.19.1