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=-4.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 6F0B4C433DF for ; Wed, 8 Jul 2020 07:41:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3CBB720656 for ; Wed, 8 Jul 2020 07:41:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3CBB720656 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 D44DB8D002C; Wed, 8 Jul 2020 03:41:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCDDC8D000D; Wed, 8 Jul 2020 03:41:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B96658D002C; Wed, 8 Jul 2020 03:41:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 9E9048D000D for ; Wed, 8 Jul 2020 03:41:07 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 61D258248D52 for ; Wed, 8 Jul 2020 07:41:07 +0000 (UTC) X-FDA: 77014112574.25.title26_1c131f326ebb Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 31D221804E3AD for ; Wed, 8 Jul 2020 07:41:07 +0000 (UTC) X-HE-Tag: title26_1c131f326ebb X-Filterd-Recvd-Size: 6018 Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Wed, 8 Jul 2020 07:41:06 +0000 (UTC) Received: by mail-ej1-f65.google.com with SMTP id f12so23107876eja.9 for ; Wed, 08 Jul 2020 00:41:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6/A3VQ/K8xvCKHiyxktO8Rg8OAtA4BCJ+I3Yp4ab7mc=; b=K6DJNRR0aX5JXpcI9rvbAuG33G8FmZChWHzOtuaTch7Sgz/f3iRGFPmIy6TomEej8T xAu+3X82PIq7JOE18Qg1AItWuPL6KjhDYD2ndJRMs0PzkeI1FIzDAysqf9hKKAm6tF+A K02extmf5YWvIUMNkD6vI1+vthxKQWkqTZ8dErEucKgsBZx9gpRpNPd4RurLMOHCBrx2 nR/UcjnePwAvgKeZ/KQ6RYLKbq5J2cTtlb4p+zSBEgonasBTDQ+LyVCpGaDV2sGZmwGi QLoJ2+bBqRVGqmRWZ4FTs2T6rQkVyvLF9EMTY3SAn1f4/g0wioRfPSf/IXDGNA3SF5Oi KJBg== X-Gm-Message-State: AOAM5300yr+SryO4sMHiOFtpvQ/fadQEHgAw4kVXXdksdcl3zCgbaSoV TpT6xnn7zOAbcT7eBKQf81E= X-Google-Smtp-Source: ABdhPJykdLeci86uEzWsDP8J/cfe/eHujJtWTsPQHzS01KxobrOSRY5slASSTgDt2Pwhj70aOnSZNA== X-Received: by 2002:a17:906:6d49:: with SMTP id a9mr48950522ejt.435.1594194065679; Wed, 08 Jul 2020 00:41:05 -0700 (PDT) Received: from localhost (ip-37-188-179-51.eurotel.cz. [37.188.179.51]) by smtp.gmail.com with ESMTPSA id dn15sm1605732ejc.26.2020.07.08.00.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 00:41:04 -0700 (PDT) Date: Wed, 8 Jul 2020 09:41:03 +0200 From: Michal Hocko To: Joonsoo Kim Cc: Vlastimil Babka , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@lge.com, Christoph Hellwig , Roman Gushchin , Mike Kravetz , Naoya Horiguchi Subject: Re: [PATCH v4 04/11] mm/hugetlb: make hugetlb migration callback CMA aware Message-ID: <20200708074103.GD7271@dhcp22.suse.cz> References: <1594107889-32228-1-git-send-email-iamjoonsoo.kim@lge.com> <1594107889-32228-5-git-send-email-iamjoonsoo.kim@lge.com> <20200708071602.GB16543@js1304-desktop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200708071602.GB16543@js1304-desktop> X-Rspamd-Queue-Id: 31D221804E3AD X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: On Wed 08-07-20 16:16:02, Joonsoo Kim wrote: > On Tue, Jul 07, 2020 at 01:22:31PM +0200, Vlastimil Babka wrote: > > On 7/7/20 9:44 AM, js1304@gmail.com wrote: > > > From: Joonsoo Kim > > > > > > new_non_cma_page() in gup.c which try to allocate migration target page > > > requires to allocate the new page that is not on the CMA area. > > > new_non_cma_page() implements it by removing __GFP_MOVABLE flag. This way > > > works well for THP page or normal page but not for hugetlb page. > > > > > > hugetlb page allocation process consists of two steps. First is dequeing > > > from the pool. Second is, if there is no available page on the queue, > > > allocating from the page allocator. > > > > > > new_non_cma_page() can control allocation from the page allocator by > > > specifying correct gfp flag. However, dequeing cannot be controlled until > > > now, so, new_non_cma_page() skips dequeing completely. It is a suboptimal > > > since new_non_cma_page() cannot utilize hugetlb pages on the queue so this > > > patch tries to fix this situation. > > > > > > This patch makes the deque function on hugetlb CMA aware and skip CMA > > > pages if newly added skip_cma argument is passed as true. > > > > Hmm, can't you instead change dequeue_huge_page_node_exact() to test the PF_ > > flag and avoid adding bool skip_cma everywhere? > > Okay! Please check following patch. > > > > I think that's what Michal suggested [1] except he said "the code already does > > by memalloc_nocma_{save,restore} API". It needs extending a bit though, AFAICS. > > __gup_longterm_locked() indeed does the save/restore, but restore comes before > > check_and_migrate_cma_pages() and thus new_non_cma_page() is called, so an > > adjustment is needed there, but that's all? > > > > Hm the adjustment should be also done because save/restore is done around > > __get_user_pages_locked(), but check_and_migrate_cma_pages() also calls > > __get_user_pages_locked(), and that call not being between nocma save and > > restore is thus also a correctness issue? > > Simply, I call memalloc_nocma_{save,restore} in new_non_cma_page(). It > would not cause any problem. I believe a proper fix is the following. The scope is really defined for FOLL_LONGTERM pins and pushing it inside check_and_migrate_cma_pages will solve the problem as well but it imho makes more sense to do it in the caller the same way we do for any others. Fixes: 9a4e9f3b2d73 ("mm: update get_user_pages_longterm to migrate pages allocated from CMA region") I am not sure this is worth backporting to stable yet. diff --git a/mm/gup.c b/mm/gup.c index de9e36262ccb..75980dd5a2fc 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1794,7 +1794,6 @@ static long __gup_longterm_locked(struct task_struct *tsk, vmas_tmp, NULL, gup_flags); if (gup_flags & FOLL_LONGTERM) { - memalloc_nocma_restore(flags); if (rc < 0) goto out; @@ -1802,11 +1801,13 @@ static long __gup_longterm_locked(struct task_struct *tsk, for (i = 0; i < rc; i++) put_page(pages[i]); rc = -EOPNOTSUPP; + memalloc_nocma_restore(flags); goto out; } rc = check_and_migrate_cma_pages(tsk, mm, start, rc, pages, vmas_tmp, gup_flags); + memalloc_nocma_restore(flags); } out: -- Michal Hocko SUSE Labs