include/linux/highmem.h

Source file repositories/reference/linux-study-clean/include/linux/highmem.h

File Facts

System
Linux kernel
Corpus path
include/linux/highmem.h
Extension
.h
Size
22430 bytes
Lines
785
Domain
Core OS
Bucket
Core Kernel Interface
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

while (len > max) {
			memset(kaddr, 0, max);
			kunmap_local(kaddr);
			len -= max;
			offset += max;
			max = PAGE_SIZE;
			kaddr = kmap_local_folio(folio, offset);
		}
	}

	memset(kaddr, 0, len);
	flush_dcache_folio(folio);

	return kaddr;
}

/**
 * folio_fill_tail - Copy some data to a folio and pad with zeroes.
 * @folio: The destination folio.
 * @offset: The offset into @folio at which to start copying.
 * @from: The data to copy.
 * @len: How many bytes of data to copy.
 *
 * This function is most useful for filesystems which support inline data.
 * When they want to copy data from the inode into the page cache, this
 * function does everything for them.  It supports large folios even on
 * HIGHMEM configurations.
 */
static inline void folio_fill_tail(struct folio *folio, size_t offset,
		const char *from, size_t len)
{
	char *to = kmap_local_folio(folio, offset);

	VM_BUG_ON(offset + len > folio_size(folio));

	if (folio_test_partial_kmap(folio)) {
		size_t max = PAGE_SIZE - offset_in_page(offset);

		while (len > max) {
			memcpy(to, from, max);
			kunmap_local(to);
			len -= max;
			from += max;
			offset += max;
			max = PAGE_SIZE;
			to = kmap_local_folio(folio, offset);
		}
	}

	memcpy(to, from, len);
	to = folio_zero_tail(folio, offset + len, to + len);
	kunmap_local(to);
}

/**
 * memcpy_from_file_folio - Copy some bytes from a file folio.
 * @to: The destination buffer.
 * @folio: The folio to copy from.
 * @pos: The position in the file.
 * @len: The maximum number of bytes to copy.
 *
 * Copy up to @len bytes from this folio.  This may be limited by PAGE_SIZE
 * if the folio comes from HIGHMEM, and by the size of the folio.
 *
 * Return: The number of bytes copied from the folio.
 */
static inline size_t memcpy_from_file_folio(char *to, struct folio *folio,
		loff_t pos, size_t len)
{
	size_t offset = offset_in_folio(folio, pos);
	char *from = kmap_local_folio(folio, offset);

	if (folio_test_partial_kmap(folio)) {
		offset = offset_in_page(offset);
		len = min_t(size_t, len, PAGE_SIZE - offset);
	} else
		len = min(len, folio_size(folio) - offset);

	memcpy(to, from, len);
	kunmap_local(from);

	return len;
}

/**
 * folio_zero_segments() - Zero two byte ranges in a folio.
 * @folio: The folio to write to.
 * @start1: The first byte to zero.
 * @xend1: One more than the last byte in the first range.
 * @start2: The first byte to zero in the second range.

Annotation

Implementation Notes