Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1476364ybh; Sun, 19 Jul 2020 21:58:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOCU2LVofRRrS/atPtI4/KswmzlItYF59GDdcSXL2AVubw1J2BBnNS/77LYlgV4NWfQY5R X-Received: by 2002:a05:6402:1a54:: with SMTP id bf20mr20096086edb.69.1595221096903; Sun, 19 Jul 2020 21:58:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595221096; cv=none; d=google.com; s=arc-20160816; b=fPlp9cDVXy+W7LQ4+CBsq+PhklENB9cUsFxv/+0upr4TSuGXQZMjXWEvfKCSx3AGq3 mOv66PCUSlUWz+t62TRzfX+44KASdzz7I83M3l5m6BdoEXvB9i0Cpb44H4VqaC3kFRFv dcVHEP1BA9WkyAAtJ2lDFE5wapsZDrS++U5cO2VJlpYvwDMHdsnfvJLFRIkFcgTKcBtd PuBsX2gxnRpnkcv1mBOeJn6FTtLrZlzidVrs3p0SfmaC464VUipFMzfkYUUoeYbObScv mt30KtMb2Hy5pHFeWLEFfQ9MOapkhv45zmltgQgto7mqfdFmvdeUK0WHofSjf3XAD11O q/eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=WxQvsZ6QmcUkdn7bmiYYmJhxUakC2I6RnR8rzuhXmYI=; b=KmfUGEpydD2YYVW9CDWJz732bJTAwg7zoYgUVLHrySRxnabzEA5RBwaR4M2PEId+dF j4ffpEnUaV6fC/rHvOM8wD+QPPfXx6G3iuBOeBBFjUyOj0XPItCDdIQcP8kQrZJO7IyJ bW6ftKfiYAigfmI8merzoJssD6M79CpkfP61ujJ+lAUc26jP/N/6RvpdkYmhq48Khx7t m3FGK5ZOPsXm16Bjkkpfhg5ae73aAUDAmXIu/ll8KscWNPX+jH2Wcyzvj+yy+LRk/P76 wieInqlcsHkQMu5yMIPgZkT6OdKae8sbu9S8pa6J+jdV2QkERrQQfltKX/oD/4VFWYYV /1Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iYXv9eft; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qp26si9974947ejb.118.2020.07.19.21.57.54; Sun, 19 Jul 2020 21:58:16 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iYXv9eft; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726587AbgGTE4r (ORCPT + 99 others); Mon, 20 Jul 2020 00:56:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725287AbgGTE4q (ORCPT ); Mon, 20 Jul 2020 00:56:46 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE67CC0619D2 for ; Sun, 19 Jul 2020 21:56:46 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id t6so8118190plo.3 for ; Sun, 19 Jul 2020 21:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WxQvsZ6QmcUkdn7bmiYYmJhxUakC2I6RnR8rzuhXmYI=; b=iYXv9eftR84ZHA/raJZbczowGT4NKjrV8526WC8U95iR7EuvEcIqalEjIbB59y3oPu OL6AvUcKU6L2I3zjzLUwCs2cAgbVakZ1QPgvgNIZOTdluu3dtek4uaCnu0oa3xzURgs/ QG7wjeVXnfxVo8JhZvFjcAFtbSfOVWVCP6WUpAacx1/q1PJCwkbVowxQTpi61dV9SOpm NPX0wCUSOtDwA7tWaflIHY3p607XyjKY+pqHlyPYUdczUX8QKOXAdFn+5ib1roKDJexC n9iFbleMRgpfi8GCy8b5Z2hdJJj1TZZ1NFx1ksaxeffoCcxYEnVAWtyJJlDE4/LxxiNT tfrA== 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; bh=WxQvsZ6QmcUkdn7bmiYYmJhxUakC2I6RnR8rzuhXmYI=; b=YHzuRIBV8KvBIKSvYoMqBiZPOLcwYLqyTmbp00R8tBk9RUhDqlhtGgyKAUAv9rjudR cH+H7BlWsBQX+hIH8F+vtbJ/jkvB2IM6/Iwh+B/VNOk1wuNCf5XHgOUsn/bHjVWfTu/W 6JUMQkoFnz2zRQF0nLiwa8dB/AnrhzTlEHsNm4zTf6wEWlQ8br4mjIzHZT+ADWOpKP2t /791883KFgt6m8HvWPNQr4ijSI+PtP0VPsdmKqdtCP4z+TXxZYyW0Ncm7C6CwyNJAWOM 8OIG5UYHJWrzFAJNkV+dxgCcdouoguCXcflzuu0ERUjJY4HBZT73YoZMqwSYB6mZRRys EmDg== X-Gm-Message-State: AOAM530vDdi7wPcE3v4KONNZ4pviwNnllroDGXwZB0RdDhczbeXIfg7B W385/zUQNU86yZBJ6w+iK9s= X-Received: by 2002:a17:90a:32cb:: with SMTP id l69mr19545057pjb.205.1595221006220; Sun, 19 Jul 2020 21:56:46 -0700 (PDT) Received: from localhost.localdomain ([114.206.198.176]) by smtp.gmail.com with ESMTPSA id w2sm10177532pjt.19.2020.07.19.21.56.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Jul 2020 21:56:45 -0700 (PDT) From: js1304@gmail.com X-Google-Original-From: iamjoonsoo.kim@lge.com To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@lge.com, Vlastimil Babka , Christoph Hellwig , Roman Gushchin , Mike Kravetz , Naoya Horiguchi , Michal Hocko , "Aneesh Kumar K . V" , Joonsoo Kim Subject: [PATCH v2 3/4] mm/hugetlb: make hugetlb migration callback CMA aware Date: Mon, 20 Jul 2020 13:56:17 +0900 Message-Id: <1595220978-9890-3-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1595220978-9890-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1595220978-9890-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joonsoo Kim new_non_cma_page() in gup.c requires to allocate the new page that is not on the CMA area. new_non_cma_page() implements it by using allocation scope APIs. However, there is a work-around for hugetlb. Normal hugetlb page allocation API for migration is alloc_huge_page_nodemask(). It consists of two steps. First is dequeing from the pool. Second is, if there is no available page on the queue, allocating by using the page allocator. new_non_cma_page() can't use this API since first step (deque) isn't aware of scope API to exclude CMA area. So, new_non_cma_page() exports hugetlb internal function for the second step, alloc_migrate_huge_page(), to global scope and uses it directly. This is suboptimal since hugetlb pages on the queue cannot be utilized. This patch tries to fix this situation by making the deque function on hugetlb CMA aware. In the deque function, CMA memory is skipped if PF_MEMALLOC_NOCMA flag is found. Acked-by: Mike Kravetz Acked-by: Vlastimil Babka Acked-by: Michal Hocko Signed-off-by: Joonsoo Kim --- include/linux/hugetlb.h | 2 -- mm/gup.c | 6 +----- mm/hugetlb.c | 11 +++++++++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 2660b04..fb2b5aa 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -509,8 +509,6 @@ struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid, nodemask_t *nmask, gfp_t gfp_mask); struct page *alloc_huge_page_vma(struct hstate *h, struct vm_area_struct *vma, unsigned long address); -struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask, - int nid, nodemask_t *nmask); int huge_add_to_page_cache(struct page *page, struct address_space *mapping, pgoff_t idx); diff --git a/mm/gup.c b/mm/gup.c index bbd36a1..4ba822a 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1634,11 +1634,7 @@ static struct page *new_non_cma_page(struct page *page, unsigned long private) struct hstate *h = page_hstate(page); gfp_mask = htlb_modify_alloc_mask(h, gfp_mask); - /* - * We don't want to dequeue from the pool because pool pages will - * mostly be from the CMA region. - */ - return alloc_migrate_huge_page(h, gfp_mask, nid, NULL); + return alloc_huge_page_nodemask(h, nid, NULL, gfp_mask); } #endif if (PageTransHuge(page)) { diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 3245aa0..d9eb923 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -1036,10 +1037,16 @@ static void enqueue_huge_page(struct hstate *h, struct page *page) static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid) { struct page *page; + bool nocma = !!(current->flags & PF_MEMALLOC_NOCMA); + + list_for_each_entry(page, &h->hugepage_freelists[nid], lru) { + if (nocma && is_migrate_cma_page(page)) + continue; - list_for_each_entry(page, &h->hugepage_freelists[nid], lru) if (!PageHWPoison(page)) break; + } + /* * if 'non-isolated free hugepage' not found on the list, * the allocation fails. @@ -1928,7 +1935,7 @@ static struct page *alloc_surplus_huge_page(struct hstate *h, gfp_t gfp_mask, return page; } -struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask, +static struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask, int nid, nodemask_t *nmask) { struct page *page; -- 2.7.4