Files
kitty/kitty/history.h
Sinity d96752e0f1 Allocate history buffer segments with mmap
glibc can raise its dynamic mmap threshold above these MB-scale allocations, routing later scrollback segments through brk. Closing windows then leaves the freed segments stranded in allocator bins and grows the long-lived kitty process.

Back the existing batched segment layout with anonymous mappings instead. This preserves zero-initialization and pointer layout while ensuring the memory is returned to the OS when a history buffer is cleared or destroyed.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-11 21:46:30 +02:00

46 lines
1.2 KiB
C

/*
* history.h
* Copyright (C) 2024 Kovid Goyal <kovid at kovidgoyal.net>
*
* Distributed under terms of the GPL3 license.
*/
#pragma once
#include "line.h"
typedef struct {
GPUCell *gpu_cells;
CPUCell *cpu_cells;
LineAttrs *line_attrs;
void *mem;
size_t mmap_size;
} HistoryBufSegment;
typedef struct {
void *ringbuf;
size_t maximum_size;
bool rewrap_needed;
} PagerHistoryBuf;
typedef struct {
PyObject_HEAD
index_type xnum, ynum, num_segments;
HistoryBufSegment *segments;
PagerHistoryBuf *pagerhist;
Line *line;
TextCache *text_cache;
index_type start_of_data, count;
} HistoryBuf;
HistoryBuf* alloc_historybuf(unsigned int, unsigned int, unsigned int, TextCache *tc);
HistoryBuf *historybuf_alloc_for_rewrap(unsigned int columns, HistoryBuf *self);
void historybuf_finish_rewrap(HistoryBuf *dest, HistoryBuf *src);
void historybuf_fast_rewrap(HistoryBuf *dest, HistoryBuf *src);
index_type historybuf_next_dest_line(HistoryBuf *self, ANSIBuf *as_ansi_buf, Line *src_line, index_type dest_y, Line *dest_line, bool continued);
bool historybuf_is_line_continued(HistoryBuf *self, index_type lnum);
void historybuf_delete_newest_lines(HistoryBuf *self, index_type count);