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=-6.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT 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 C3710C433DB for ; Tue, 22 Dec 2020 09:21:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D9BA2311D for ; Tue, 22 Dec 2020 09:21:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D9BA2311D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 981936B0098; Tue, 22 Dec 2020 04:21:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 930486B009D; Tue, 22 Dec 2020 04:21:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 847BD6B009F; Tue, 22 Dec 2020 04:21:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id 6CCCA6B0098 for ; Tue, 22 Dec 2020 04:21:23 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 30A42180AD837 for ; Tue, 22 Dec 2020 09:21:23 +0000 (UTC) X-FDA: 77620374846.28.foot19_3b070b92745e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 1216E6C1A for ; Tue, 22 Dec 2020 09:21:23 +0000 (UTC) X-HE-Tag: foot19_3b070b92745e X-Filterd-Recvd-Size: 2982 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Dec 2020 09:21:22 +0000 (UTC) Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4D0W5v0JSFz7Hs8; Tue, 22 Dec 2020 17:20:35 +0800 (CST) Received: from huawei.com (10.174.176.179) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Tue, 22 Dec 2020 17:21:10 +0800 From: wangbin To: , , , CC: Subject: mm: thp: free memory is less than expected due to partial unmap. Date: Tue, 22 Dec 2020 17:21:04 +0800 Message-ID: <20201222092104.1084-1-wangbin224@huawei.com> X-Mailer: git-send-email 2.29.2.windows.3 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.176.179] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable 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: In commit eef1b3ba053a("thp: implement split_huge_pmd()"): "Original split_huge_page() combined two operations: splitting PMDs i= nto tables of PTEs and splitting underlying compound page. This patch implements split_huge_pmd() which split given PMD without splitting other PMDs this page mapped with or underlying compound page." In this situation, suppose a process is allocated a large number of trans= parent huge pages and it releases partial memory of these huge pages later. The = memory occupied by the process will decrease after split_huge_pmd(). However, th= e free memory of the system may not increase because the huge page has not = been split. In addition, the rss in the memory.stat of the cgroup which the pr= ocess belongs to is much larger than expected. This causes some problems: - Users cannot get exact size of free memory to evaluate the system's workloads. - The memory usage of service is unstable due to unpredictable partial = unmap of transparent huge pages. We are not sure if there is memory leak or o= ther problems. Here is an example: # cat memory.stat ... rss 297230336 rss_huge 230686720 ... # echo 2 > /proc/sys/vm/drop_caches (this can split some transpanrent hug= e pages) # cat memory.stat ... rss 118128640 rss_huge 27262976 ... As memory.stat shows, memory usage before split huge pages is more than t= wice the actual memory usage. Two possible solutions: - Provide the split_huge_page_pmd() again and add a sysfs interface for= users to choose split_huge_page_pmd() or split_huge_pmd() when releasing memo= ry of transparent huge pages. - Add a statistics item to /proc/meminfo and memory cgroup to display t= he memory released of partial unmap so that users can calculate the actual= free memory of the current system. I haven't implemented the patch yet. Hope there's a better solution.