// SPDX-License-Identifier: GPL-2.0
/*
 *	linux/mm/mlock.c
 *
 *  (C) Copyright 1995 Linus Torvalds
 *  (C) Copyright 2002 Christoph Hellwig
 */

/* Extracted unchanged from Linux v6.0, mm/mlock.c:103-120.
 * Complete function definition; surrounding kernel context is required.
 * Source: https://github.com/torvalds/linux/blob/v6.0/mm/mlock.c#L103
 * License text: GPL-2.0.txt (in this directory).
 */
static struct lruvec *__mlock_new_page(struct page *page, struct lruvec *lruvec)
{
	VM_BUG_ON_PAGE(PageLRU(page), page);

	lruvec = folio_lruvec_relock_irq(page_folio(page), lruvec);

	/* As above, this is a little surprising, but possible */
	if (unlikely(page_evictable(page)))
		goto out;

	SetPageUnevictable(page);
	page->mlock_count = !!PageMlocked(page);
	__count_vm_events(UNEVICTABLE_PGCULLED, thp_nr_pages(page));
out:
	add_page_to_lru_list(page, lruvec);
	SetPageLRU(page);
	return lruvec;
}

