From patchwork Tue May 24 02:53:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 12859631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9870CC433EF for ; Tue, 24 May 2022 02:54:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 239526B0074; Mon, 23 May 2022 22:54:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E7E86B0075; Mon, 23 May 2022 22:54:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AE6E6B0078; Mon, 23 May 2022 22:54:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EA7F86B0074 for ; Mon, 23 May 2022 22:54:01 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id A9523811E8 for ; Tue, 24 May 2022 02:54:01 +0000 (UTC) X-FDA: 79499117082.19.A9780EF Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf20.hostedemail.com (Postfix) with ESMTP id 9CDA21C001D for ; Tue, 24 May 2022 02:53:46 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id r14-20020a17090a1bce00b001df665a2f8bso583095pjr.4 for ; Mon, 23 May 2022 19:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=q3rEJi6AIjzJ+bUAJZeMcmdUxWHE4S/Q88M4Ua28yEk=; b=YC2Xx0t8OKDK5LZEma9gZe76vMNsvwMAu5meYbmXYK1L781bjAMEFLEd/u9aMWeUdM CTVQx1DMzitmh/sM5Q9Cm6cM8zV7SvupiE46i8y1OrRxmi1H1FEJXb2IUFkPGVvNkci4 xzhfohOZz8CU4i8Knz9YW8q/jWiteSjgGsfz9DZlmV7tlzUEW906RJz0MvXSM22hayJl qZS56zp2Jr7AIzEB0K+BsVafV6ElB3JloaSgxatxZhcpbWk+aHfq7Cani8WE2RBfpvu7 rPHiJkoqOlj8u11f4HT3/RxH7ZvRxegYrhrLo+abx4JqNmsyn/Q0AJMnIKPRjS+XRMd5 pqiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=q3rEJi6AIjzJ+bUAJZeMcmdUxWHE4S/Q88M4Ua28yEk=; b=wZAaL/IJ1XxzZ3RsCjkjI5U4UBqrRqvrHp8e7A2evDu8maZRyrF/3rmmBeljHxZcu+ 8m8RrRNuM7YTS6CYzk8dPZG0Ls9tGuA/zbqa6OfXMzP57qu1bovf5Z+CABwVNzQi1jXP qM/0H/UACbGrrsDtmgwQV+8TQhZHPTR+BKg+TAQ7JXyPLqgZR9xBf5upMri3O3wHeKLK sBLz3Muxrx/loX65eXiBsRt/waVhxCYmsjp8U2uOBtgkD5TSBi4wIQptJDD58biO+IFR yto3D1A63bxYImQ7p+ducsHBNZu9WKXMEttiyt8TbBs2zg0bH9GbKfU58sQGVNROxksw wUuw== X-Gm-Message-State: AOAM531XHkymPYm5mginhcbVhKCqRWiOTKwaGlkA44ImrIkHJxJBERRZ +77S23L9pY8cWermvSo+v96Nwa3BPySA6A== X-Google-Smtp-Source: ABdhPJyIfH+Joy+m2RnKyWjOTFi5d/N4oyCgli7DdQUdhTvSVV1Yk2dlHH9Mxl8Z7KeVK7bT708/u8FVzZHLVA== X-Received: from yjqkernel.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1837]) (user=jiaqiyan job=sendgmr) by 2002:a17:902:ccd0:b0:156:7ac2:5600 with SMTP id z16-20020a170902ccd000b001567ac25600mr25403994ple.156.1653360840136; Mon, 23 May 2022 19:54:00 -0700 (PDT) Date: Mon, 23 May 2022 19:53:50 -0700 Message-Id: <20220524025352.1381911-1-jiaqiyan@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog Subject: [PATCH v3 0/2] Memory poison recovery in khugepaged collapsing From: Jiaqi Yan To: shy828301@gmail.com, tongtiangen@huawei.com Cc: tony.luck@intel.com, naoya.horiguchi@nec.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, juew@google.com, jiaqiyan@google.com, linux-mm@kvack.org X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 9CDA21C001D X-Stat-Signature: ek6seqme3e6r3jqiqfx571cbtrg33ndw Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YC2Xx0t8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3yEiMYggKCKUONFVNdFSLTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--jiaqiyan.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3yEiMYggKCKUONFVNdFSLTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--jiaqiyan.bounces.google.com X-Rspam-User: X-HE-Tag: 1653360826-644384 X-Bogosity: Ham, tests=bogofilter, spamicity=0.116346, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Problem ======= Memory DIMMs are subject to multi-bit flips, i.e. memory errors. As memory size and density increase, the chances of and number of memory errors increase. The increasing size and density of server RAM in the data center and cloud have shown increased uncorrectable memory errors. There are already mechanisms in the kernel to recover from uncorrectable memory errors. This series of patches provides the recovery mechanism for the particular kernel agent khugepaged when it collapses memory pages. Impact ====== The main reason we chose to make khugepaged collapsing tolerant of memory failures was its high possibility of accessing poisoned memory while performing functionally optional compaction actions. Standard applications typically don't have strict requirements on the size of its pages. So they are given 4K pages by the kernel. The kernel is able to improve application performance by either 1) giving applications 2M pages to begin with, or 2) collapsing 4K pages into 2M pages when possible. This collapsing operation is done by khugepaged, a kernel agent that is constantly scanning memory. When collapsing 4K pages into a 2M page, it must copy the data from the 4K pages into a physically contiguous 2M page. Therefore, as long as there exists one poisoned cache line in collapsible 4K pages, khugepaged will eventually access it. The current impact to users is a machine check exception triggered kernel panic. However, khugepaged’s compaction operations are not functionally required kernel actions. Therefore making khugepaged tolerant to poisoned memory will greatly improve user experience. This patch series is for cases where khugepaged is the first guy that detects the memory errors on the poisoned pages. IOW, the pages are not known to have memory errors when khugepaged collapsing gets to them. In our observation, this happens frequently when the huge page ratio of the system is relatively low, which is fairly common in virtual machines running on cloud. Solution ======== As stated before, it is less desirable to crash the system only because khugepaged accesses poisoned pages while it is collapsing 4K pages. The high level idea of this patch series is to skip the group of pages (usually 512 4K-size pages) once khugepaged finds one of them is poisoned, as these pages have become ineligible to be collapsed. We are also careful to unwind operations khuagepaged has performed before it detects memory failures. For example, before copying and collapsing a group of anonymous pages into a huge page, the source pages will be isolated and their page table is unlinked from their PMD. These operations need to be undone in order to ensure these pages are not changed/lost from the perspective of other threads (both user and kernel space). As for file backed memory pages, there already exists a rollback case. This patch just extends it so that khugepaged also correctly rolls back when it fails to copy poisoned 4K pages. Changelog ========= v3 changes - Incorporate feedbacks from Yang Shi - Add tracepoint for __collapse_huge_page_copy - Correct comment about mmap_read_lock v2 changes - Incorporate feedbacks from Yang Shi - Only keep copy_highpage_mc - Adding new scan_result SCAN_COPY_MC - Defer NR_FILE_THPS update until copying succeeded Jiaqi Yan (2): mm: khugepaged: recover from poisoned anonymous memory mm: khugepaged: recover from poisoned file-backed memory include/linux/highmem.h | 19 +++ include/trace/events/huge_memory.h | 27 +++- mm/khugepaged.c | 223 +++++++++++++++++++++-------- 3 files changed, 206 insertions(+), 63 deletions(-)