Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2356897ybh; Fri, 24 Jul 2020 10:43:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDjlCzU6HWkkjkr0kE+IWfOeIZkdvqUIqakSLBUW8D2qnwzOLrCo7dHf798AtJuP+eavO2 X-Received: by 2002:a05:6402:1716:: with SMTP id y22mr2772174edu.301.1595612596395; Fri, 24 Jul 2020 10:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595612596; cv=none; d=google.com; s=arc-20160816; b=EMgTHwJeo6bl1au6Ue/0KDaP0NFXQA/nDyQOXRORvgyMVEYf94/1FwL+MNFzh7YLFE 9pekfa+54255xyxu3tJBTMehKrLGSn8TK2xVhEBzNpOw9b9BPfSL1a4pDurqcRwK2K2q S9znWyfskJvZjVlkPV2cYNOsZHUF0uLXkwBJgS5W6os3MHb9RJIqUZyw10G+hIXns5i2 CqWfLcUtwn3OC+PZ4EeUEb4ZbyWzd8Na0Ixifv0RMH4ViRI82xTuIzRNkoTQFO8RnBnq EQ/zajD9yiqadSlRxkTusBnAROijkIti6CmPJQ487jENJkoIqj8fCIrzSwZCiWt9vt4b SyEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=Fr8EKy7VqOliLP6BaZi+i9GsbdCbaRb1CNW+FV6l/Qw=; b=GDrHK0jb5jRJ2IkV3GBRFQ8ygPz6j+9r6q90LcaH1r77WL2bfM5XuV1iMkmXIg69/u ue3OWzKIbWzGdD4janGG+s7I/PRoOE9F7nA8bSbagrupZmV0Se95FzIiq7F8g1t7xkiY WXoNQKfPh3u8jmnwK7JWZgZkIRIL2MluBUiwy9R9kNh1ZA0ioJnsj2KYnQcS3zuM7cPb umjCktUnlKnuwMA+tjRvhpITL8JNd70yTBToCtWE2TDIH7creVbfF9s7kE8kTQrQwX+w WucdfiFWuea88Fa2DiE5CwMU3sbLx7yiPhZQuTJKA11Zzrp3V+RBxHqW6Boi89DXJH4a 7E6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=FZbkSRuM; 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=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c19si976060ejz.484.2020.07.24.10.42.53; Fri, 24 Jul 2020 10:43: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=@oracle.com header.s=corp-2020-01-29 header.b=FZbkSRuM; 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=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727812AbgGXRll (ORCPT + 99 others); Fri, 24 Jul 2020 13:41:41 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:38974 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726455AbgGXRlk (ORCPT ); Fri, 24 Jul 2020 13:41:40 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06OHRg9d169013; Fri, 24 Jul 2020 17:41:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=Fr8EKy7VqOliLP6BaZi+i9GsbdCbaRb1CNW+FV6l/Qw=; b=FZbkSRuMFauOjlwa5atPu5dfKM4qj/c1bf9cRfMxq4lzJJ0jxO42JMeKfEEuYUhJN2FR OvUvkt+2fa+3x180kuZfyBFTsvIzYyFFYb2hItRPohRrQvU7u1aSUCxPaepM9GTvmylO +qThWreG7xVEXQKOfKKjpd+KTsfoq51tIun0f8raXDg7Wb1XCfgAYpPvCDtC2UWRzUEi okdv9kWEitbRiwZQh+VZYiLymribSItP0Q/AnzfR7XPcoInLijdOWe9YUcL3nxATd+7R ppw9lWm6pflionKuq8VVAoZaxwMA83GylAHIlWvX5UiBnqDhzPfTVvzUrDpzOUwCZFEB bQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 32d6kt4mq4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 24 Jul 2020 17:41:23 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06OHOPPg130870; Fri, 24 Jul 2020 17:41:22 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 32ft2vpw9s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jul 2020 17:41:22 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06OHfFfj017456; Fri, 24 Jul 2020 17:41:16 GMT Received: from [192.168.2.112] (/50.38.35.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 24 Jul 2020 17:41:15 +0000 Subject: Re: [PATCH v2] mm/hugetlb: add mempolicy check in the reservation routine To: Muchun Song , akpm@linux-foundation.org, mhocko@kernel.org Cc: rientjes@google.com, mgorman@suse.de, walken@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jianchao Guo References: <20200724100306.33457-1-songmuchun@bytedance.com> From: Mike Kravetz Message-ID: <609f2de6-b91f-0018-cf98-18524a34b5d2@oracle.com> Date: Fri, 24 Jul 2020 10:41:14 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200724100306.33457-1-songmuchun@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9692 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 spamscore=0 bulkscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007240132 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9692 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=2 bulkscore=0 mlxscore=0 mlxlogscore=999 impostorscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 spamscore=0 adultscore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007240132 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/24/20 3:03 AM, Muchun Song wrote: > In the reservation routine, we only check whether the cpuset meets > the memory allocation requirements. But we ignore the mempolicy of > MPOL_BIND case. If someone mmap hugetlb succeeds, but the subsequent > memory allocation may fail due to mempolicy restrictions and receives > the SIGBUS signal. This can be reproduced by the follow steps. > > 1) Compile the test case. > cd tools/testing/selftests/vm/ > gcc map_hugetlb.c -o map_hugetlb > > 2) Pre-allocate huge pages. Suppose there are 2 numa nodes in the > system. Each node will pre-allocate one huge page. > echo 2 > /proc/sys/vm/nr_hugepages > > 3) Run test case(mmap 4MB). We receive the SIGBUS signal. > numactl --membind=0 ./map_hugetlb 4 > > With this patch applied, the mmap will fail in the step 3) and throw > "mmap: Cannot allocate memory". > > Reported-by: Jianchao Guo > Signed-off-by: Muchun Song Michal has already provides some good suggestions. > @@ -3653,7 +3666,7 @@ static int hugetlb_acct_memory(struct hstate *h, long delta) > if (gather_surplus_pages(h, delta) < 0) > goto out; > > - if (delta > cpuset_mems_nr(h->free_huge_pages_node)) { > + if (delta > allowed_mems_nr(h)) { > return_unused_surplus_pages(h, delta); > goto out; > } There is a big comment before this code in hugetlb_acct_memory. The comment only talks about cpusets. We should probably update that to include mempolicy as well. It could be as simple as s/cpuset/cpuset or mempolicy/. -- Mike Kravetz